<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/4/27
 * Time: 10:08
 */

namespace app\adminapiv3\controller;


class IpsWebsiteProtect extends Base
{

    /**
     * @name 站点列表
     * @param $hostId
     * @author wx
     * @date 2020/4/27 10:21
     */
    public function list($hostId)
    {
        $params['domain_name'] = $this->filterInput('domain_name', 'post');
        $params['description'] = $this->filterInput('description', 'post');
        $params['website_path'] = $this->filterInput('website_path', 'post');
        $params['file_protect'] = $this->filterInput('file_protect', 'post');
        $params['create'] = $this->filterInput('create', 'post');
        $params['modify'] = $this->filterInput('modify', 'post');
        $params['del'] = $this->filterInput('del', 'post');
        $params['status'] = $this->filterInput('status', 'post');

        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $data = $server->list($hostId, $params, $this->getLimit());

        $this->jsonOutPut($data);
    }

    /**
     * @name 列表首页数据
     * @author wx
     * @date 2020/4/27 10:23
     */
    public function data()
    {
        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $data = $server->data();

        $this->jsonOutPut($data);
    }

    /**
     * @name 站点添加
     * @author wx
     * @date 2020/4/27 10:38
     */
    public function add()
    {
        global $logContent;
        $logContent = '添加防篡改策略';

        $insertData['host_id'] = $this->filterInput('host_id*','post');//主机id
        $insertData['domain_name'] = $this->filterInput('domain_name','post', '');//域名
        $insertData['descirption'] = $this->filterInput('descirption','post', '');//描述
        $insertData['website_path'] = $this->filterInput('website_path*','post');//网站路径
        $insertData['file_protect'] = $this->filterInput('file_protect*','post');//文件保护
        $insertData['create'] = $this->filterInput('create*','post');//创建
        $insertData['modify'] = $this->filterInput('modify*','post');//修改
        $insertData['del'] = $this->filterInput('del*','post');//删除
        $insertData['status'] = $this->filterInput('status*','post');//是否开启


        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $data = $server->add($insertData);

        $this->jsonOutPut($data,true);

        //通知中间件
        $this->Async('Defense','TpRules');
    }

    /**
     * @name 详情
     * @author wx
     * @date 2020/4/27 10:53
     */
    public function info()
    {
        $id = $this->filterInput('id*','post');
        $hostId = $this->filterInput('host_id*','post');

        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $info = $server->info($id, $hostId);

        $this->jsonOutPut($info);
    }

    /**
     * @name 删除
     * @author wx
     * @date 2020/4/27 10:41
     */
    public function del()
    {
        global $logContent;
        $logContent = '删除防篡改策略';

        $id = $this->filterInput('id*','post');
        $host_id = $this->filterInput('host_id*','post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $server->del($id);

        $this->jsonOutPut([], true);

        //通知中间件
        $this->Async('Defense','TpRules');
    }

    /**
     * @name 重新导入站点
     * @author wx
     * @date 2020/4/27 10:46
     */
    public function delHostId()
    {
        global $logContent;
        $logContent = '重新导入防篡改策略';

        $hostId = $this->filterInput('host_id*','post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($hostId);

        $server = new \app\adminapiv3\service\IpsWebsiteProtect();
        $server->delHostId($hostId);

        $this->jsonOutPut();

        //通知中间件
        $this->Async('Defense','Import');
    }

    /**
     * @name 修改
     * @author wx
     * @date 2020/4/27 10:57
     */
    public function modify()
    {
        global $logContent;
        $logContent = '修改防篡改策略';

        //接收参数
        $id = $this->filterInput('id*','post');

        $updata['host_id'] = $this->filterInput('host_id*','post');
        $updata['status'] = $this->filterInput('status*','post');
        $updata['domain_name'] = $this->filterInput('domain_name','post', '');
        $updata['descirption'] = $this->filterInput('description','post', '');
        $updata['website_path'] = $this->filterInput('website_path*','post');
        $updata['file_protect'] = $this->filterInput('file_protect*','post');
        $updata['create'] = $this->filterInput('create*','post');
        $updata['modify'] = $this->filterInput('modify*','post');
        $updata['del'] = $this->filterInput('del*','post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($updata['host_id']);

        $service = new \app\adminapiv3\service\IpsWebsiteProtect();
        $service->modify($id, $updata);

        $this->jsonOutPut([], true);

        //通知中间件
        $this->Async('Defense','TpRules');
    }


}